<!DOCTYPE html>
            
<HTML>
<HEAD>
<meta name="booktitle" content="Developing Applications With Objective Caml" >
 <meta charset="ISO-8859-1"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<META name="GENERATOR" content="hevea 1.05-7 of 2000-02-24">
<META NAME="Author" CONTENT="Christian.Queinnec@lip6.fr">
<LINK rel=stylesheet type="text/css" href="videoc-ocda.css">
<script language="JavaScript" src="videoc.js"><!--
//--></script>
<TITLE>
 Introduction
</TITLE>
</HEAD>
<BODY class="regularBody">
<A HREF="book-ora022.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora025.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2> Introduction</H2>In contrast to functional programming, in which you calculate a value by
applying a function to its arguments without caring how the operations are
carried out, imperative programming is closer to the machine representation,
as it introduces memory state which the execution of the program's actions
will modify. We call these actions of programs instructions, and an
imperative program is a list, or sequence, of instructions. The
execution of each operation can alter the memory state. We consider
input-output actions to be modifications of memory, video
memory, or files.<BR>
<BR>
This style of programming is directly inspired by assembly programming. You
find it in the earliest general-purpose programming languages (Fortran,
C, Pascal, etc.). In Objective CAML the following elements of the language
fit into this model:<BR>
<BR>
<UL>
<LI>
 modifiable data structures, such as arrays, or records with
 mutable fields;

<LI> input-output operations;

<LI> control structures such as loops and exceptions.
</UL>
Certain algorithms are easier to write in this programming style. Take for
instance the computation of the product of two matrices. Even though it is
certainly possible to translate it into a purely functional version, 
in which lists replace vectors, this is neither natural nor efficient 
compared to an imperative version.<BR>
<BR>
The motivation for the integration of imperative elements into a functional 
language is to be able to write certain algorithms in this style when it is 
appropriate. The two principal disadvantages, compared to the purely functional
style, are:<BR>
<BR>
<UL>
<LI>
 complicating the type system of the language, and rejecting certain
 programs which would otherwise be considered correct;<BR>
<BR>

<LI> having to keep track of the memory representation and of the order of
 calculations.</UL>
Nevertheless, with a few guidelines in writing programs, the
choice between several programming styles offers the greatest flexibility
for writing algorithms, which is the principal objective of any programming
language. Besides, a program written in a style which is close to the 
algorithm used will be simpler, and hence will have a better chance of
being correct (or at least, rapidly correctable).<BR>
<BR>
For these reasons, the Objective CAML language has some types of data structures whose
values are physically modifiable, structures for controlling the execution
of programs, and an I/O library in an imperative style.<BR>
<BR>
<HR>
<A HREF="book-ora022.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora025.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
